//
//  DNTabBarViewController.m
//  DanoneEA
//
//  Created by Senela on 16/9/20.
//  Copyright © 2016年 翔傲科技. All rights reserved.
//

#import "DNTabBarViewController.h"
#import "TTINavigationController.h"
#import "ICUser.h"
#import "UIColor+Utils.h"
#import "HUD.h"
#import "AppMacro.h"
#import "UIImage+Utils.h"


@interface DNTabBarViewController ()<UITabBarControllerDelegate>

@end

@implementation DNTabBarViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    int siteInfo = 1; //arc4random()%6;
    
    NSMutableArray *controllersArr = [NSMutableArray array];
    
    //home vc
    UIStoryboard *home = [UIStoryboard storyboardWithName:@"DNHome" bundle:nil];
    TTINavigationController *homeNav1 = [home instantiateInitialViewController];
    UITabBarItem *tabBarItem1 = [self createWithTitle:DNNSLocalizedString(@"NavTitle_Home",@"") image:@"ic_home" seletedImage:@"ic_home_sel"];
    homeNav1.tabBarItem = tabBarItem1; 
    [controllersArr addObject:homeNav1];
    
    
    if(siteInfo<2)
    {
        //crying vc
        UIStoryboard *classificaiton = [UIStoryboard storyboardWithName:@"DNCrying" bundle:nil];
        TTINavigationController *homeNav2 = [classificaiton instantiateInitialViewController];
        UITabBarItem *tabBarItem2 = [self createWithTitle:DNNSLocalizedString(@"NavTitle_Crying",@"") image:@"ic_select" seletedImage:@"ic_select_sel"];
        homeNav2.tabBarItem = tabBarItem2;
        [controllersArr addObject:homeNav2];
    }
    
    if(siteInfo<3)
    {
        //stool vc
        UIStoryboard *person = [UIStoryboard storyboardWithName:@"DNStool" bundle:nil];
        TTINavigationController *homeNav3 = [person instantiateInitialViewController];
        UITabBarItem *tabBarItem3 = [self createWithTitle:DNNSLocalizedString(@"NavTitle_Stool",@"") image:@"ic_shop" seletedImage:@"ic_shop_sel"];
        homeNav3.tabBarItem = tabBarItem3;
        
        [controllersArr addObject:homeNav3];
    }
    
    if(siteInfo<4)
    {
        //feeding vc
        UIStoryboard *shopCar = [UIStoryboard storyboardWithName:@"DNFeeding" bundle:nil];
        TTINavigationController *homeNav4 = [shopCar instantiateInitialViewController];
        UITabBarItem *tabBarItem4 = [self createWithTitle:DNNSLocalizedString(@"NavTitle_Feeding",@"") image:@"ic_profile" seletedImage:@"ic_profile_sel"];
        homeNav4.tabBarItem = tabBarItem4;
        [controllersArr addObject:homeNav4];
    }
    
    if(siteInfo<5)
    {
    }
    
    if(siteInfo<6)
    {
    }
    
    // 字体颜色 选中
    [[UITabBarItem appearance] setTitleTextAttributes:@{NSFontAttributeName : [UIFont fontWithName:@"HelveticaNeue-Bold" size:12.0F], NSForegroundColorAttributeName : TAB_BAR_COLOR} forState:UIControlStateSelected];
    
    // 字体颜色 未选中
    [[UITabBarItem appearance] setTitleTextAttributes:@{NSFontAttributeName : [UIFont systemFontOfSize:12.0F],  NSForegroundColorAttributeName:[UIColor grayColor]} forState:UIControlStateNormal];
    
    self.tabBar.tintColor = TABBAR_TXT_COLOR;
    self.viewControllers = controllersArr;
    self.delegate = self;
    
    
    //去掉tabbar顶部黑线
    //    [self.tabBar setBackgroundImage:[UIImage createImageWithColor:[UIColor whiteColor]]];
    //    self.tabBar.translucent = NO;
    //    [self.tabBar setShadowImage:[[UIImage alloc] init]];
    
}


/**
 *  generate UITabBarItem  for NavigationController
 *
 *  @param title   the title for UITabBarItem
 *  @param image   the image for unselected button
 *  @param selectedImage  the image for selelcted button
 *
 *  @return UITabBarItem
 */
- (UITabBarItem *)createWithTitle:(NSString *)title image:(NSString *)image seletedImage:(NSString *)selectedImage
{
    UITabBarItem *barItem = [[UITabBarItem alloc]initWithTitle:title image:[[UIImage imageNamed:image]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] selectedImage:[[UIImage imageNamed:selectedImage]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
    
    // set the title styles
    NSMutableDictionary *textAttrs = [NSMutableDictionary dictionary];
    textAttrs[NSForegroundColorAttributeName] = [UIColor colorForHex:@"666666"];
    textAttrs[NSFontAttributeName] = FontSize_12;
    NSMutableDictionary *selectTextAttrs = [NSMutableDictionary dictionary];
    selectTextAttrs[NSForegroundColorAttributeName] = [UIColor colorForHex:@"ed3c2d"];
    selectTextAttrs[NSFontAttributeName] = FontSize_12;
    [barItem setTitleTextAttributes:textAttrs forState:UIControlStateNormal];
    [barItem setTitleTextAttributes:selectTextAttrs forState:UIControlStateSelected];
    
    return barItem;
}

-(BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController
{
    return YES;
}


- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
    
}

@end
